-
-
Notifications
You must be signed in to change notification settings - Fork 241
Fix/ns views not cleaned on removal #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/ns views not cleaned on removal #1740
Conversation
…iptRendererFactory is destroyed
Make sure outlets and currentOutlet are removed when the NSLocationStrategy is destroyed.
When removing the children from a Label and one of these children is a FormattedString, the FormattedTextProperty throw this exception: "TypeError: Cannot read property 'textTransform' of undefined"
Without this the Page and componentView doesn't get the proper relation for then the page is destroyed.
…onent PageRouterOutlet.loadComponentInPage moves the componentView from its native parent, to the Page. Don't remove the componentView's children when it is removed from the native parent.
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
Just like with FormattedString this throws an exception
Upon reviewing #1767, I realized that This was usually not an issue, but when we navigate out (and this actually happens with livesync too), the modal will never close. Maybe the modal should also be destroyed on
Or maybe this should be handled by tns-core-modules on |
I wanted to checkout the behavior, unfortunately I have trouble running But I'm thinking |
Hi @edusperoni, Do you have an example where I have been trying to replicate the problem without any success. EDIT: |
I think this is mainly an issue when livesyncing. If you do:
and livesync, it'll go back to page 1 and not close the modal. But I don't think it's something that should be considered in this PR |
|
||
if (this.isActivated) { | ||
const c = this.activated.instance; | ||
this.activated.hostView.detach(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no need to call detach
on component that will be destroyed anyway
Hey there @m-abs The only change I didn't completely understand is |
That is unfortunately needed to clear up all references to It might help if I give an example. If we have a UI-tree like this:
This gives us these references:
Removing
(To simplify the example I left out the |
Shouldn't only the parent and siblings be updated then?
Since there is no more reference to View1_1_1, the whole tree should be GCed. |
I've added a simple example to illustrate this behavior: https://stackblitz.com/edit/typescript-pbquxj How to check garbage collection:
The same exercise could be done in the NativeScript runtime with |
Back when I started this PR, we had serious memory issues. It ended up delaying a release. My stress test project as mentioned here could very easily crash. It would take about 1300 iterations or ~15 mins. The behavior between The stress test app no longer crash due to low memory, but it does end up using too much memory after many iterations. I've been testing on Android using the Chrome Debugger to take heap snapshots manually. (I wish, I knew a better way to do it). My reasoning behind removing the UI-tree recursively like that, was to make it easier for the Views to be My guess is/was that are circular references in the sub-tree that makes it more difficult than needed for the Originally I just removed the
I also tried making those properties into
@edusperoni But GC takes longer, without recursively removing the child views. I've run three stress tests with 1000 iterations. 1st test is with 2nd test is my PR without recursively removing children: 3rd test is with my PR as-is: ~7000ms less time spend on GC, if I remove the children recursively. |
Indeed! The recursive remove does produce better results. I have also tried the same test with Note: Adding That said - I'm sold on keeping the recursive remove. I have some other minor suggestions and we can merge this. |
I tried
But that belongs in another issue :)
Cool :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Thanks @m-abs |
test ios@rc |
test ios@rc |
test ios#rc |
PR Checklist
What is the current behavior?
See the description in #1738
What is the new behavior?
ViewUtil.removeChild(parent, child)
now removes children recursively to clear references.TemplatedItemsComponent.ngOnDestroy()
empties the_templateMap
to remove a circular reference to theTemplatedItemsComponent
in the factory functions.PageRouterOutlet.ngOnDestroy()
will now destroy the activated componentRef.NativeScriptRendererFactory.ngOnDestroy()
will now destroy the children of the rootNgView.NSLocationStrategy.ngOnDestroy()
removes its outlets.Fixes #1738
Related to #1728